//
// Created by Alex on 2021/12/1.
//

#include "GeoPolyLine.h"

GeoPolyLine::GeoPolyLine() {

}

void GeoPolyLine::addPoint(LonLat p) {
    this->pts.append(p);
}

void GeoPolyLine::addProperties(QString key, QVariant value){
    this->properties.insert(key,value);
}

QVariant GeoPolyLine::getPropertiesValue(QString key)
{
    if(properties.contains(key))
        {
            return properties.value(key);
        }else{
            return "NULL";
    }
}

void GeoPolyLine::setStyle(GeoStyle *style){
    this->lineStyle = style;
}

void GeoPolyLine::getScale()
{
    Xmin=pts.at(0).getLongitude();
        Xmax=pts.at(0).getLongitude();
        Ymin=pts.at(0).getLatitude();
        Ymax=pts.at(0).getLatitude();
        for(int i=0;i<pts.size();i++)
        {
            if(pts.at(i).getLongitude()>Xmax)    Xmax=pts.at(i).getLongitude();
            if(pts.at(i).getLongitude()<Xmin)    Xmin=pts.at(i).getLongitude();
            if(pts.at(i).getLatitude()>Ymax)     Ymax=pts.at(i).getLatitude();
            if(pts.at(i).getLatitude()<Ymin)     Ymin=pts.at(i).getLatitude();
        }
        mmRect = GeoScale(Xmin,Ymin,Xmax,Ymax);
}

QList<LonLat> GeoPolyLine::getData()
{
    return this->pts;
}

double GeoPolyLine::getR()
{
    if(lineStyle != nullptr)
        return lineStyle->fillCcolor.red()/255.0;
    return 1.0;
}

double GeoPolyLine::getG()
{
    if(lineStyle != nullptr)
        return lineStyle->fillCcolor.green()/255.0;
    return 1.0;
}

double GeoPolyLine::getB()
{
    if(lineStyle != nullptr)
        return lineStyle->fillCcolor.blue()/255.0;
    return 1.0;
}

double GeoPolyLine::getLineWidth()
{
    if(lineStyle != nullptr)
        return lineStyle->strokeWidth;
    return 2.0;
}
